home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
BARNET
/
COMPILER
/
SATHER
/
!Sather
/
Library
/
Base
/
test
/
sa
/
int
< prev
next >
Wrap
Text File
|
1996-05-08
|
3KB
|
89 lines
---------------------------> Sather 1.1 source file <--------------------------
-- test_int.sa:
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>
-- Copyright (C) 1995, International Computer Science Institute
-- $Id: int_test.sa,v 1.4 1996/05/08 08:34:43 borisv Exp $
--
-- COPYRIGHT NOTICE: This code is provided WITHOUT ANY WARRANTY
-- and is subject to the terms of the SATHER LIBRARY GENERAL PUBLIC
-- LICENSE contained in the file: Sather/Doc/License of the
-- Sather distribution. The license is also available from ICSI,
-- 1947 Center St., Suite 600, Berkeley CA 94704, USA.
-------------------------------------------------------------------
class TEST_INT is
include TEST;
main is
class_name("INT");
a ::= 5;
b ::= 7;
tp: FSTR := #;
restp ::= 1101.str_in(tp,10,8,'#');
test("1101.str_in",restp,"######2115");
tp2: FSTR := #;
restp2 ::= 1101.str_in(tp2,10,16,'#');
test("1101.str_in(hex)",restp2,"#######44D");
tp3: FSTR := #;
restp3 ::= INT::nil.str_in(tp3,12,10,'#');
test("nil.str_in(10)",restp3,"#-2147483648");
tp4: FSTR := #;
restp4 ::= INT::nil.str_in(tp4,12,16,'#');
test("nil.str_in(16)",restp4,"###-80000000");
tp5: FSTR := #;
restp5 ::= INT::nil.str_in(tp5,16,8,'#');
test("nil.str_in(16)",restp5,"####-20000000000");
val ::= a.plus(b);
test("plus",val.str,"12");
test("plus",(a+b).str,"12");
test("minus",(a-b).str,"-2");
test("negate",(-a).str,"-5");
test("times",(a*b).str,"35");
test("div",(b/a).str,"1");
test("mod",(b.mod(a)).str,"2");
test("is_eq",(b=a).str,"false");
test("is_eq",(a=a).str,"true");
-- neq --- missing routines...
-- ...
-- Iter routines
i::=0; loop 9.times!; i:= i+1; end;
test("times!",i.str,"9");
res::=""; loop res := res+5.times!+" "; end;
test("times!:SAME",res,"0 1 2 3 4 ");
res:=""; loop res := res+5.for!(4)+" "; end;
test("for!",res,"5 6 7 8 ");
res:=""; loop res := res+5.upto!(10)+" "; end;
test("upto!",res,"5 6 7 8 9 10 ");
res:=""; loop res := res+5.downto!(1)+" "; end;
test("downto",res,"5 4 3 2 1 ");
res:=""; loop res := res+5.step!(3,4)+" "; end;
test("step",res,"5 9 13 ");
i:=0; loop i := 0.sum!(5.step!(3,4)); end;
test("sum!",i.str,"27");
i:=0; loop i := 0.product!(5.step!(3,4)); end;
test("product!",i.str,"585");
res:=""; loop res := res+1.stepto!(10,2)+" "; end;
test("stepto!",res.str,"1 3 5 7 9 ");
res:=""; loop res := res+0.stepto!(10,2)+" "; end;
test("stepto!",res.str,"0 2 4 6 8 10 ");
res:=""; loop res := res+10.stepto!(0,-2)+" "; end;
test("step(down)to!",res.str,"10 8 6 4 2 0 ");
test("pow 2^8",2.pow(8).str,256.str);
cur ::= 0;
cur_pow ::= 1;
loop
30.times!;
test("pow 2^"+cur,2.pow(cur).str,cur_pow.str);
cur := cur + 1;
cur_pow := cur_pow*2;
end;
finish;
end;
end; -- class TEST_INT
-------------------------------------------------------------------